using DimensionsHelper.LanguageService.Symbols;
using DimensionsHelper.LanguageService.Syntax;

namespace DimensionsHelper.LanguageService;

public class AnalysisDoStatement : AnalysisStatement
{
    internal AnalysisDoStatement(DoStatement syntaxNode,
        AnalysisExpression condition,
        AnalysisBlock body,
        AnalysisNode? parent) :
        base(AnalysisBoundKinds.DoStatement, syntaxNode, parent)
    {
        Syntax = syntaxNode;

        Condition = condition;
        Condition.Parent = this;

        Body = body;
        Body.Parent = this;
    }

    public AnalysisExpression Condition { get; }

    public AnalysisBlock Body { get; }

    public override int ChildrenCount => 2;

    public override DoStatement Syntax { get; }

    public override IEnumerable<AnalysisNode> GetChildren()
    {
        return [Condition, Body];
    }

    internal override void AddChild(AnalysisNode child)
    {
        throw new NotSupportedException("AnalysisDoStatement is read-only.");
    }
}

public static partial class AnalysisNodeFactory
{
    /// <summary>
    /// 创建一个Do循环语句
    /// </summary>
    /// <param name="syntaxNode">原始语法节点</param>
    /// <param name="condition">条件表达式</param>
    /// <param name="body">循环语句体</param>
    /// <param name="parent">父节点，可以忽略</param>
    /// <param name="withSymbol">语法节点所在的With语句上下文类型符号</param>
    public static AnalysisDoStatement DoStatement(DoStatement syntaxNode,
        AnalysisExpression condition,
        AnalysisBlock body,
        AnalysisNode? parent,
        ITypeSymbol? withSymbol)
    {
        return new AnalysisDoStatement(syntaxNode, condition, body, parent).WithContainingWithSymbol(withSymbol);
    }
}